package cn.le.crawler.ali;

import cn.le.enums.EnumAuctionMode;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class AliPropertyUtil {

    //地区
    private static final Map<String,String> AREA_MAP;
    static {
        AREA_MAP = new HashMap<String,String>(){{
            put("四川","spm=a213w.7398504.filter.24.1f0065fdHeWDBy");
            put("北京","spm=a213w.7398504.filter.47.2b2865fdwQZFtD");
            put("天津","spm=a213w.7398504.filter.28.38d73d88wlDCcN");
            put("河北","spm=a213w.7398504.filter.29.1cd17e7bR7gCMn");
            put("山西","spm=a213w.7398504.filter.40.29125e43FJhaD8");
            put("辽宁","spm=a213w.7398504.filter.30.4f4c4245BSZjdb");
            put("内蒙古","spm=a213w.7398504.filter.41.6fa0564eSTS6fo");
            put("吉林","spm=a213w.7398504.filter.46.20d74245rHlbv1");
            put("黑龙江","spm=a213w.7398504.filter.32.56981467OUdhcc");
            put("上海","spm=a213w.7398504.filter.47.5eac146724eQtA");
            put("江苏","spm=a213w.7398504.filter.34.7619fb3fWC14AI");
            put("浙江","spm=a213w.7398504.filter.35.11f54a758YLpBG");
            put("安徽","spm=a213w.7398504.filter.36.6d8e1bedAbCHCF");
            put("福建","spm=a213w.7398504.filter.51.7c49fb3f5E9tP1");
            put("江西","spm=a213w.7398504.filter.48.6c92128ad0xHwo");
            put("山东","spm=a213w.7398504.filter.39.1b876715nkpe8Y");
            put("河南","spm=a213w.7398504.filter.58.6dd367154zY1m7");
            put("湖北","spm=a213w.7398504.filter.60.6b7361a6DANnQk");
            put("湖南","spm=a213w.7398504.filter.42.4be450d5ACiQiM");
            put("广东","spm=a213w.7398504.filter.43.318e44fdlsCwMv");
            put("广西","spm=a213w.7398504.filter.44.58681ed2NHrBX1");
            put("海南","spm=a213w.7398504.filter.45.49d6657f63Oszg");
            put("重庆","spm=a213w.7398504.filter.46.4479533aJewkTM");
            put("贵州","spm=a213w.7398504.filter.47.69fa721ciuiWif");
            put("云南","spm=a213w.7398504.filter.48.772f19c9rb3IA7");
            put("西藏","spm=a213w.7398504.filter.49.30cb6fe756noKA");
            put("陕西","spm=a213w.7398504.filter.58.32fd6fe7T4pv4P");
            put("甘肃","spm=a213w.7398504.filter.51.5262498dhaFdg7");
            put("青海","spm=a213w.7398504.filter.52.489762c0XOarOm");
            put("宁夏","spm=a213w.7398504.filter.53.73321e21VNC4ky");
            put("新疆","spm=a213w.7398504.filter.54.71d6f721VWLOph");
        }};
    }
    private static final int PAGE_SUM = 45;
    //请求地址
    private static final String URL = "https://sf.taobao.com/item_list.htm";

    //https://zc-paimai.taobao.com/list/0____%B3%C9%B6%BC___56950002.htm?spm=a219w.7474998.filter.21.3f643c54P74ASb&auction_source=0&st_param=-1&auction_start_seg=-1

    //房源详情url
    static final String ITEM_URl = "https://sf-item.taobao.com/sf_item/";
    //备用房源详情url
    static final String SPARE_ITEM_URL ="https://susong-item.taobao.com/auction/";

    private static final String URL_PARAM = "&category=50025969&auction_source=0&province=%CB%C4%B4%A8&st_param=-1&auction_start_seg=-1&page=";

    //地区url映射
    private static Map<String,String> areaUrlMap = new HashMap<>();
    //模式url映射
    private static Map<String, EnumAuctionMode> modeUrlMap = new HashMap<>();

    static List<String> getUrls(){
        List<String> urls = new LinkedList<>();
        AREA_MAP.forEach((key,val)->{
            StringBuilder sb = new StringBuilder();
            sb.append(URL).append("?").append(val).append(URL_PARAM);
            for (int i = 1; i <= PAGE_SUM; i++) {
                urls.add(new StringBuilder(sb).append(i).toString());
            }
        });
        return urls;
    }

    static String getItemUrl(long id){
        return ITEM_URl + id + ".htm?spm=a213w.7398504.paiList.1.61573458TwhCSU";
    }

    static String getSpareItemUrl(long id){
        return SPARE_ITEM_URL + id + ".htm?spm=a213w.7398504.paiList.1.61573458TwhCSU";
    }

    static String getPicUrl(String url) {
        return "https:" + url;
    }
}
